﻿Public Class LuongNhanVien
    Private xllnv As XLLuongNV
    Private data As DataTable
    Private dsnv As List(Of DTO_NhanVienCT.NhanVien)
    Private vt As Integer
    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lv_lnv.SelectedIndexChanged
        Try
            tb_manv.Text = lv_lnv.SelectedItems(0).SubItems(1).Text()
            tb_hoten.Text = lv_lnv.SelectedItems(0).SubItems(2).Text()
            tb_cvu.Text = lv_lnv.SelectedItems(0).SubItems(3).Text()
            tb_lcb.Text = lv_lnv.SelectedItems(0).SubItems(4).Text()
            tb_ngcong.Text = lv_lnv.SelectedItems(0).SubItems(5).Text()
            tb_ngnghi.Text = lv_lnv.SelectedItems(0).SubItems(6).Text()
            tb_tenpc.Text = lv_lnv.SelectedItems(0).SubItems(7).Text()
            tb_pc.Text = lv_lnv.SelectedItems(0).SubItems(8).Text()
            tb_hs.Text = lv_lnv.SelectedItems(0).SubItems(9).Text()
            tb_tncn.Text = lv_lnv.SelectedItems(0).SubItems(10).Text()
            tb_bhxh.Text = lv_lnv.SelectedItems(0).SubItems(11).Text()
            tb_bhyt.Text = lv_lnv.SelectedItems(0).SubItems(12).Text()
            tb_tlanh.Text = lv_lnv.SelectedItems(0).SubItems(13).Text()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub LuongNhanVien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        showR()
    End Sub

    Private Sub bt_lammoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_lammoi.Click
        xllnv = New XLLuongNV
        data = New DataTable
        dsnv = New List(Of DTO_NhanVienCT.NhanVien)
        data = xllnv.BUS_TaoMoi(data, DateTime.Now.Month & "/" & DateTime.Now.Year, dsnv)
        showL()
    End Sub

    Private Sub bt_xem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_xem.Click
        If tb_manv.Text <> "" And tb_hoten.Text <> "" Then
            'tim theo ma va ten
            For i As Integer = 0 To lv_lnv.Items.Count - 1
                If lv_lnv.Items(i).SubItems(1).Text() = tb_manv.Text And lv_lnv.Items(i).SubItems(2).Text() = tb_hoten.Text Then
                    vt = i
                    LV_click()
                End If
            Next
        ElseIf tb_manv.Text <> "" Then
            'tim theo ma
            For i As Integer = 0 To lv_lnv.Items.Count - 1
                If lv_lnv.Items(i).SubItems(1).Text() = tb_manv.Text Then
                    vt = i
                    LV_click()
                End If
            Next
        Else
            'tim theo ten
            For i As Integer = 0 To lv_lnv.Items.Count - 1
                If lv_lnv.Items(i).SubItems(2).Text() = tb_hoten.Text Then
                    vt = i
                    LV_click()
                End If
            Next
        End If
    End Sub

    Private Sub bt_Lamlai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Lamlai.Click
        Rfesh()
    End Sub

    Private Sub reload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reload.Click
        showR()
    End Sub
    Private Sub showR()
        xllnv = New XLLuongNV
        data = New DataTable
        dsnv = New List(Of DTO_NhanVienCT.NhanVien)
        data = xllnv.BUS_AllLuong(DateTime.Now.Month & "/" & DateTime.Now.Year)
        lv_lnv.Items.Clear()
        lv_lnv.View = View.Details
        lv_lnv.GridLines = True
        lv_lnv.FullRowSelect = True
        If data.Rows.Count <> 0 Then
            Dim tong As Double = 0
            For Each dr As DataRow In data.Rows
                Dim item As New ListViewItem
                item.Text = "STT"
                item.SubItems.Add(dr("MaNV"))
                item.SubItems.Add(dr("HoTen"))
                item.SubItems.Add(dr("CVu"))
                item.SubItems.Add(dr("LCB"))
                item.SubItems.Add(dr("NgCong"))
                item.SubItems.Add(dr("NgNghi"))
                item.SubItems.Add(dr("TPCap"))
                item.SubItems.Add(dr("PCap"))
                item.SubItems.Add(dr("HSo"))
                item.SubItems.Add(dr("TTNCN"))
                item.SubItems.Add(dr("BHXH"))
                item.SubItems.Add(dr("BHYT"))
                item.SubItems.Add(dr("TongThuNhap"))
                tong += Convert.ToDouble(dr("TongThuNhap"))
                lv_lnv.Items.Add(item)
                capnhatSTT()
            Next
        End If
    End Sub
    Private Sub showL()
        Dim tong As Double = 0
        lv_lnv.Items.Clear()
        lv_lnv.View = View.Details
        lv_lnv.GridLines = True
        lv_lnv.FullRowSelect = True
        For Each nv As DTO_NhanVienCT.NhanVien In dsnv
            For Each dr As DataRow In data.Rows
                If dr("MLuong") = nv.Mluong Then
                    Dim item As New ListViewItem
                    item.Text = "STT"
                    item.SubItems.Add(nv.MaNV)
                    item.SubItems.Add(nv.HoTen)
                    item.SubItems.Add(nv.ChucVu)
                    item.SubItems.Add(dr("LCB"))
                    item.SubItems.Add(dr("NgCong"))
                    item.SubItems.Add(dr("NgNghi"))
                    item.SubItems.Add(dr("TPCap"))
                    item.SubItems.Add(dr("PCap"))
                    item.SubItems.Add(dr("HSo"))
                    item.SubItems.Add(dr("TTNCN"))
                    item.SubItems.Add(dr("BHXH"))
                    item.SubItems.Add(dr("BHYT"))
                    item.SubItems.Add(dr("TongThuNhap"))
                    tong += Convert.ToDouble(dr("TongThuNhap"))
                    lv_lnv.Items.Add(item)
                    capnhatSTT()
                End If
            Next
        Next
        tb_tongchi.Text = tong
    End Sub
    Private Sub capnhatSTT()
        For i As Integer = 1 To lv_lnv.Items.Count
            lv_lnv.Items(i - 1).Text = i.ToString
        Next
    End Sub
    Private Sub Rfesh()
        tb_manv.Text = String.Empty
        tb_hoten.Text = String.Empty
        tb_cvu.Text = String.Empty
        tb_lcb.Text = String.Empty
        tb_ngcong.Text = String.Empty
        tb_ngnghi.Text = String.Empty
        tb_tenpc.Text = String.Empty
        tb_pc.Text = String.Empty
        tb_hs.Text = String.Empty
        tb_tncn.Text = String.Empty
        tb_bhxh.Text = String.Empty
        tb_bhyt.Text = String.Empty
        tb_tlanh.Text = String.Empty
    End Sub
    Private Sub LV_click()
        Try
            tb_manv.Text = lv_lnv.Items(vt).SubItems(1).Text
            tb_hoten.Text = lv_lnv.Items(vt).SubItems(2).Text
            tb_cvu.Text = lv_lnv.Items(vt).SubItems(3).Text
            tb_lcb.Text = lv_lnv.Items(vt).SubItems(4).Text
            tb_ngcong.Text = lv_lnv.Items(vt).SubItems(5).Text
            tb_ngnghi.Text = lv_lnv.Items(vt).SubItems(6).Text
            tb_tenpc.Text = lv_lnv.Items(vt).SubItems(7).Text
            tb_pc.Text = lv_lnv.Items(vt).SubItems(8).Text
            tb_hs.Text = lv_lnv.Items(vt).SubItems(9).Text
            tb_tncn.Text = lv_lnv.Items(vt).SubItems(10).Text
            tb_bhxh.Text = lv_lnv.Items(vt).SubItems(11).Text
            tb_bhyt.Text = lv_lnv.Items(vt).SubItems(12).Text
            tb_tlanh.Text = lv_lnv.Items(vt).SubItems(13).Text
        Catch ex As Exception
        End Try

    End Sub


    Private Sub close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cclose.Click
        Me.Close()
    End Sub

   
End Class



'tb_manv.Text = lv_lnv.SelectedItems(0).SubItems(1).Text()
'            tb_hoten.Text
'            tb_cvu.Text
'            tb_lcb.Text
'            tb_ngcong.Text
'            tb_ngnghi.Text
'            tb_tenpc.Text
'            tb_pc.Text
'            tb_hs.Text
'            tb_tncn.Text
'            tb_bhxh.Text
'            tb_bhyt.Text
'            tb_tlanh.Text